package com.chaos.eurekaproducer.test;

import com.chaos.eurekaproducer.domain.User;

import java.lang.reflect.Field;

/**
 * @author liaopeng
 * @title: SynchronizedDemo
 * @projectName eureka-producer
 * @description: TODO
 * @date 2021/7/26下午5:54
 */
public class ReflectDemo {

    public static void main(String[] args){
        try {
            Class<User> userClass = User.class;
            Field field = userClass.getDeclaredField("name");
            User user = new User();
            field.setAccessible(true);
            System.out.println("赋值前："+field.get(user));
            field.set(user,"xiaye");
            System.out.println("赋值后："+field.get(user));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
